#include<cstdio>//uncle-lu
#include<cstring>
#include<cmath>
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

int n, m;
long long int F[210];

int main()
{
	read(n);read(m);

	memset(F, 0x7f7f, sizeof(F));
	F[0] = 0;

	int a, b;
	for (int i = 1; i <= m; i++) 
	{
		read(a);read(b);
		for (int j = n; j >= 1; j--) 
			for (int k = 1; k <= j; k++) 
				F[j] = std::min(F[j], F[j-k] + a * (long long int)pow(k, b));
	}

	printf("%lld", F[n]);
	return 0;
}
